package day10;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class ArrayListDemo {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(10);
        list.add("ok");
        list.add(null);
        list.add("ok");
        System.out.println(list);

        List<String> list2 = new ArrayList<String>();
        list2.add("python");
        list2.add("python");
        list2.add("java");
        list2.add(null);
        System.out.println(list2);

        List<Book> books = new ArrayList<>();
        Book b1 = new Book(1,"1001","java",100.0d);
        Book b2 = new Book(2,"1002","python",200.0d);
        Book b3 = new Book(3,"1003","mybatis",300.0d);
        books.add(b1);
        books.add(b2);
        books.add(b3);

        System.out.println(books.size());

        System.out.println(books.isEmpty());

        Book b4 = new Book(3,"1004","spring",300.0d);
        System.out.println(books.contains(b4));

        System.out.println(books.indexOf(b3));

        for(int i = 0; i < books.size();i++){
            System.out.println(books.get(i));
        }
        System.out.println("----");

        for(Book book : books){
            System.out.println(book);
        }
        System.out.println("---");
        books.forEach(b-> System.out.println(b));
        System.out.println("===foreach===");
        books.forEach(System.out::println);
        System.out.println("===迭代器====");

        Iterator<Book> iter = books.iterator();
        while(iter.hasNext()){
            Book b = iter.next();
            System.out.println(b);
        }
    }
}
